/**
 *	\file
 *	\brief represents a single class resource in the symbol table
 *
 * 	\date Aug 30, 2013
 * 	\author koldar
 */

#ifndef RESOURCEELEMENT_H_
#define RESOURCEELEMENT_H_

#include <stdbool.h>
#include <stdio.h>
#include "schema.h"
#include "ResourceClassType.h"
#include "IdentifierList.h"
#include "LocalResourceHashTable.h"

/**represents a single resource of a class
 *
 */
typedef struct ResourceElement {
	ResourceClassType class; //!<indicates what exactly is this resource Element
	char* name; //!< indicates the name of this ResourceElement
	unsigned int oid; //!< The Object IDentifier represents uniquely any resourceElement
	bool isAbstract; //!< if set to TRUE indicates that this resource is abstract
	bool isStatic; //!< if set to TRUE indicates that this resource is static: this means that the field is owned by the <b>very</b> class itself, not only by the various instances
	PidentifierList readGroup;//!< indicates a series of pointer to strings stored in the label table representing the groups which can read this resource
	PidentifierList writeGroup; //!< indicates a series of pointer to strings stored in the label table representing the groups which can write this resource
	Pschema schema; //!< indicates the type of this resource
	LocalResourceHashTable localEnvironment; //!< if the resource is a function, points to a space where local variable and parameters are defined
	unsigned short vararg; //!< if the resource is a function, indicates the number of parameters
	LocalResourceList formalParams; //!< if the resource is a function, points to a list of the resource in the local environment representing the formal parameters
} ResourceElement;

/**pointer to a ResourceElement
 *
 */
typedef ResourceElement* PresourceElement;

/**creates a new resource for a class to be inserted in a hash table
 *
 *	\pre
 *	 \li name not NULL
 *	 \li every label stored in _readGroup is not NULL
 *	 \li every label stored in _writeGroup is not NULL
 *	 \li vararg must not be negative
 *	\post
 *	 \li a ResourceElement is stored in memory. Must be freed with freeResourceElement()
 *
 * @param _class the type of the resource
 * @param _name the name of the resource
 * @param _isAbstract TRUE if the resource is abstract, FALSE otherwise
 * @param _isStatic TRUE if the resource is static, FALSE otherwise
 * @param _schema the type of this resource, NULL if the resource is VOID
 * @param _readGroup a list of label groups which can read this object
 * @param _writeGroup a list of label groups which can write this object
 * @param _vararg the number of formal parameters this resource has
 * @param _localEnvironment a pointer to a hash table storing all the local parameters this resource has
 * @param _formalParams a list of formal parameters this resource has
 * @return a pointer to a newly created resource element
 */
PresourceElement initResourceElement(ResourceClassType _class,char* _name,bool _isAbstract, bool _isStatic, Pschema _schema,PidentifierList _readGroup,PidentifierList _writeGroup,unsigned short _vararg,PlocalResourceHTCell _localEnvironment,LocalResourceList _formalParams);

/**frees the selected ResourceElement
 *
 * \pre
 *  \li pobj must not be NULL
 * \post
 *  \li pobj is correctly deallocated from the memory
 *
 * @param pobj the memory to be freed
 */
void freeResourceElement(PresourceElement pobj);

/**print a stirng representation of the ResourceElement passed
 *
 * \pre
 *  \li f must be open in write mode
 * \post
 *  \li f is changed
 *
 * @param f the file to write the object on
 * @param pobj the object to be printed
 */
void printResourceElement(FILE* f,PresourceElement pobj);

//TODO documentation
void generateDOTResourceElement(FILE* f,PresourceElement pobj,int* nodenumber,int* cellnumber,int format);

#endif /* RESOURCEELEMENT_H_ */
